//进行路由的初始化 和 配置
//导入
import VueRouter from 'vue-router'
//注册
import Vue from 'vue'

//工具
import auth from '@/utils/auth'

//导入组件
import Login from '@/views/login'
import Home from '@/views/home'
import Welcome from '@/views/welcome'
import NoFound from '@/views/404'
import Article from '@/views/article'
import Image from '@/views/image'
import Publish from '@/views/publish'
import Comment from '@/views/comment'
import Fans from '@/views/fans'
import Setting from '@/views/setting'
// import auth from '../utils/auth'


Vue.use(VueRouter)
//初始化
const router = new VueRouter({
    routes: [
        {path: '/login',component:Login},
        {path: '/',component:Home , children : [
            {path: '/',component:Welcome},
            {path: '/article',component:Article},
            {path: '/image',component:Image},
            {path: '/publish',component:Publish},
            {path: '/comment',component:Comment},
            {path: '/fans',component:Fans},
            {path: '/setting',component:Setting}
        ]},
        {path: '*',component:NoFound},
        
    ]
})

//前置导航守卫
router.beforeEach((to,from,next) => {
    if (to.path !== '/login' && !auth.getUser().token) return next('/login')

    next()
})

//导出
export default router
